package com.flydog.mall.common.api;

import lombok.Data;
import org.springframework.data.domain.Page;

import java.util.List;

/**
 * @author Cao
 * @description 分页数据响应封装类
 * @create 2021-03-19
 */
@Data
public class PageResponse<T> {
    private Integer pageNum;
    private Integer pageSize;
    private Integer totalPage;
    private long total;
    private List<T> list;


    public static <T> PageResponse<T> restPage(Page<T> pageInfo) {
        PageResponse<T> result = new PageResponse<>();
        result.setList(pageInfo.getContent());
        result.setPageNum(pageInfo.getNumber());
        result.setPageSize(pageInfo.getSize());
        result.setTotal(pageInfo.getTotalElements());
        result.setTotalPage(pageInfo.getTotalPages());
        return result;
    }
}
